package com.xhsj.user.sms.purchase.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xhsj.user.sms.purchase.entity.TbPurchaseOrderSubtask;
import com.xhsj.user.sms.purchase.service.TbPurchaseOrderSubtaskService;
import com.xhsj.user.sms.purchase.vo.MyFindOrderSuntaskListVo;
import com.xhsj.user.utils.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

//import org.springframework.security.access.prepost.PreAuthorize;


/**
 * <p>
 * 采购订单子任务 前端控制器
 * </p>
 *
 * @author suxiaolin
 * @since 2020-06-11
 */
@Slf4j
@Api(tags = "采购订单子任务")
@RestController
@RequestMapping("/purchase/tbPurchaseOrderSubtask")
public class TbPurchaseOrderSubtaskController {

	@Autowired
    public TbPurchaseOrderSubtaskService service;
//
//
//	@ApiOperation(value = "采购订单子任务,保存/修改", notes = "采购订单子任务,保存和修改方法")
//	@RequestMapping(value = "/save", method = RequestMethod.POST)
//    //@PreAuthorize("hasAuthority('tb:purchase:order:subtask:edit')")
//	public Message save(@RequestBody TbPurchaseOrderSubtask data){
//    	try {
//    		service.save(data);
//			return Message.success("成功");
//		} catch (Exception e) {
//			log.error("保存失败:{}",e);
//        	return Message.error(1,"失败");
//		}
//
//	}

//
//	@ApiOperation(value = "采购订单子任务删除", notes = "通过id删除采购订单子任务信息。")
//	@RequestMapping(value = "/delete", method = RequestMethod.GET)
//    //@PreAuthorize("hasAuthority('tb:purchase:order:subtask:delete')")
//	public Message delete(@RequestParam(value="id") String id) {
//		try {
//			service.removeById(id);
//        	return Message.success("成功");
//		} catch (Exception e) {
//			log.error("删除失败:{}",e);
//            return Message.error(1,"失败");
//		}
//
//	}
//
//	@ApiOperation(value = "批量删除", notes = "批量删除。")
//	@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
//	public Message batchDelete(@RequestBody List<String> list) {
//		try {
//			service.removeByIds(list);
//    		return Message.success("成功");
//		} catch (Exception e) {
//    		log.error("删除失败:{}",e);
//    		return Message.error(1,"失败");
//		}
//    }

	@ApiOperation(value = "分页查询采购订单子任务list", notes = "带参数查询,{\"page\": 1,\"size\": 5,......}。支持模糊查询")
	@RequestMapping(value="/findList",method = RequestMethod.POST)
    //@PreAuthorize("hasAuthority('tb:purchase:order:subtask:view')")
	public Message findList(@RequestBody Map<String,Object> data) {
        try {
        	IPage<TbPurchaseOrderSubtask> selectPage = service.selectPage(data);
    		return Message.success("成功",selectPage.getRecords(),selectPage.getTotal(),selectPage.getPages());
        } catch (Exception e) {
			log.error("查询异常:{}",e);
    		return Message.error(1,"失败");
        }
	}

	@ApiOperation(value = "查询采购订单子任务所有数据list", notes = "查询采购订单子任务所有数据list。")
	@RequestMapping(value="/findAll",method = RequestMethod.POST)
    //@PreAuthorize("hasAuthority('tb:purchase:order:subtask:view')")
	public Message findAll(){
        return Message.success("成功",service.selectAll());
	}


	@ApiOperation(value = "通过id获取采购订单子任务实体类", notes = "通过id获取采购订单子任务实体类。")
	@RequestMapping(value="/getById",method = RequestMethod.GET)
    //@PreAuthorize("hasAuthority('tb:purchase:order:subtask:view')")
	public Message getById(@RequestParam(value="id") String id) {
    	return Message.success("成功",service.getById(id));
	}

	@ApiOperation(value = "通过id获取实体类详细信息", notes = "通过id获取实体类详细信息。")
	@RequestMapping(value="/detail",method = RequestMethod.GET)
    //@PreAuthorize("hasAuthority('tb:purchase:order:subtask:view')")
	public Message detail(@RequestParam(value="id") String id) {
    	return Message.success("成功",service.getById(id));
	}

	@ApiOperation(value = "分页查询我的采购订单子任务list", notes = "带参数查询,{\"page\": 1,\"size\": 5,......}。支持模糊查询")
	@RequestMapping(value="/myFindOrderSuntaskList",method = RequestMethod.POST)
	public Message myFindOrderSuntaskList(@RequestBody Map<String,Object> data) {
		try {
			IPage<MyFindOrderSuntaskListVo> selectPage = service.myFindOrderSuntaskList(data);
			return Message.success("成功",selectPage.getRecords(),selectPage.getTotal(),selectPage.getPages());
		} catch (Exception e) {
			log.error("查询异常:{}",e);
			return Message.error(1,"失败");
		}
	}

}

